import { Router } from "express";
import type { Response } from "express";

//請求後返回數據
interface ReturnMessage {
  code: number; //status
  message: string;
  data: Array<{ [key: string]: number | string }>; //返回數據,鍵值對數組
}

//操作數據庫的參數定義
interface CapOptions {
  sql: string;
  params?: Array<paramsType>;
  isMulti?: boolean;
}

interface paramsType {
   name:string;
   value:number | string;
}

//自定義封裝路由
interface CapRouter {
  url: string;
  fn: (router: Router, callbackFn: CapCallbackFn) => Router;
}

//請求後的囘調函數
interface CapCallbackFn {
  (res: Response, options: CapOptions): void;
}

//定义回调函数的参数函数类型
interface Capfn {
  (options: CapOptions): Promise<ReturnMessage>;
}

//操作數據庫的囘調函數
interface DbOperation {
  dbConnect: Capfn;
}

//驗證碼
interface ValidCode {
  timeRecord: number;
  validCode: string;
  userName: string;
}

interface SendEmail {
  from: string;
  to: string;
  subject: string;
  html: string;
}

export {
  ReturnMessage,
  CapRouter,
  CapCallbackFn,
  DbOperation,
  CapOptions,
  ValidCode,
  SendEmail,
  paramsType
};
